<template>
  <div class='limitedTimePurchase'>
    <div class='background'><img src="https://image.hezongyy.com/pcimage/20211109img/ten_h5_bg.png" alt="">
      <div class='btn'>
        <!-- <img src="https://image.hezongyy.com/pcimage/20211109img/20211109mj_btn_app.png" alt="" > -->
          <div class='changeBtn' v-if="this.purchasedataList&&this.purchasedataList[0]&&this.purchasedataList[0].receive==0" @click='gotoApp(0)'>立即抢购</div>
           <div class='changeBtn' v-else @click='gotoApp(1)'>查看优惠券</div>
          <!-- <img src="https://image.hezongyy.com/pcimage/20211109img/ckyhj_h5.png" alt=""> -->
      </div>
    </div>
  </div>
</template>
<script>
//引入保存所有接口的url文件
import url from '../../../axios/apiUrl'
//引入api.js定义的方法index
import { postRequest } from '../../../api/index'
import { getRequest } from '../../../api/indexGet'
export default {
  data() {
    return {
      purchasedataList: [],
    }
  },
  created() {},

  mounted() {
      this.purchaseList()
  },

  methods: {
    async purchaseList() {
      let res = await getRequest(url.purchaseList)
      if (res.data.code == '000000') {
      this.purchasedataList = res.data.content
      }
      if (res.data.message == '系统异常') {
        this.$toast('网络异常，请稍后再试')
      } else if (res.data.code != '000000') {
        this.$toast(res.data.message)
      }
    },
    gotoApp(type) {
      var isIos = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) //ios终端
      // type=0  立即购买  type=1 查看优惠券
      if (type == 0) {
        if (
          this.purchasedataList[0] &&
          this.purchasedataList[0].receiveStatus == 1
        ) {
          this.$toast('活动未开始~')
          return
        }
        if (isIos) {
          if (this.purchasedataList[0]) {
            let form = this.purchasedataList[0]
            window.webkit.messageHandlers.showBuyTenCouponAlert.postMessage(
              form
            )
          }
        } else {
          if (this.purchasedataList[0]) {
            let form = this.purchasedataList[0]
            japp.placeCoupon(form.id)
          }
        }
      } else if (type == 1) {
        window.location.href = this.pathURL + 'nativeApp/couponCenter'
      }
    },
  },
}
</script>
<style lang="less" scoped src='./index.less'>
</style>